dojo.declare("MVendorOrderHistoryPg", wm.Page, {
    start: function() {
        this.selectDays.setDataValue(1);
        // this.reloadMyOrders(-1);
    },
    "preferredDevice": "phone",

    reloadMyOrders: function(days) {
        var mainPage = wm.Page.getPage("MobileMainPg");

        this.svVendorOrderHistory.input.setValue("vendorId", mainPage.vUserId);
        this.svVendorOrderHistory.input.setValue("statusNew ", "Delivered");
        this.svVendorOrderHistory.input.setValue("statusPartly ", "Partly Delivered");
        var currDate = new Date();
        var prevDate = dojo.date.add(currDate, "day", days);

        this.svVendorOrderHistory.input.setValue("prevDate", prevDate);
        this.svVendorOrderHistory.update();

    },
    selectDaysChange: function(inSender, inDisplayValue, inDataValue, inSetByCode) {

        var days = inDataValue * -1;

        this.reloadMyOrders(days);

    },
    list1OrderIdFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        var comment = '';
        if (rowObj.comments !== null) {
            comment = rowObj.comments;
        }
        var block = '';
        if (rowObj.customerByCustomerId.block !== null) {
            block = rowObj.customerByCustomerId.block.blockName;
        }
        var door = '';
        if (rowObj.customerByCustomerId.door !== null) {
            door = rowObj.customerByCustomerId.door.doorName;
        }
        var display = "<div style='display:block;font-weight: normal;'>Order#:<b> " + rowObj.orderId + "</b></div>" + "<div class='MobileRow'>" + wm.List.prototype.dateFormatter({
            "formatLength": "medium",
            "dateType": "date and time"
        }, null, null, null, rowObj.orderDt) + "</div>" +

        "<div style='display:block;font-weight: normal;'> TotalPrice: <b>" + rowObj.totalPrice + "</b></div>" + "<div style='display:block;font-weight: normal;'> Customer: <b>" + rowObj.customerByCustomerId.name + "</b></div>" + "<div style='display:block;font-weight: normal;'> Ph:<b>" + rowObj.customerByCustomerId.primaryPhone + "</b></div>" + "<div style='display:block;font-weight: normal;'> Address: Block <b>" + block + ' Door ' + door + " </b></div>" + "<div style='display:block;font-weight: normal;'> Status:<b>" + rowObj.status + "</b></div>" + "<div style='display:block;font-weight: normal;'> Comments:<b>" + comment + "</b></div>";


        return display;
    },
    list1StatusFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        var display = "<div class='MobileRowTitle'><b>Status :</b> </br> " + rowObj.status + "</div>";
        return display;
    },

    list2OrderItemIdFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        var comments = '';
        if (rowObj.comments !== null) {

            comments = rowObj.comments;
        }

        var display = "<div style='display:block;font-weight: normal;'> <b>" + rowObj.quantity + " " + rowObj.items.itemName + " Price: " + rowObj.price + " Rs </b></div>";
        //  "</b></div>" + "<div style='display:block;font-weight: normal;'>Quantity: <b>" + rowObj.quantity + 
        //  "</b>  Price: <b>" + rowObj.price + " Rs </b></div>";
        //+        "<div style='display:block;font-weight: normal;'>Comments: <b>" + comments + "</b></div>";
        var unit = rowObj.items.unit;

        if (!unit || unit === null) {
            unit = "";
        }
        display = " <div style='display:block;font-weight: normal;'> <b> &nbsp;&nbsp;";
        display = display + rowObj.items.itemName + "," + rowObj.price + "Rs (" + rowObj.quantity + " " + unit + " @" + rowObj.items.price + "Rs)";
        display = display + "</br> ";
        display = display + "</b></div> ";
        return display;
    },

    list3OrderIdFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {

        var comment = '';
        if (rowObj.comment !== null) {
            comment = rowObj.comment;
        }
        var vendor_comment = '';
        if (rowObj.vendor_comment !== null) {
            vendor_comment = rowObj.vendor_comment;
        }
        var block = '';
        if (rowObj.blockName !== null) {
            block = rowObj.blockName;
        }
        var door = '';
        if (rowObj.doorName !== null) {
            door = rowObj.doorName;
        }
        var display = "<div style='display:block;font-weight: normal;'>Order#:<b> " + rowObj.orderId + "</b></div>" + "<div class='MobileRow'>" + wm.List.prototype.dateFormatter({
            "formatLength": "medium",
            "dateType": "date and time"
        }, null, null, null, rowObj.orderDt) + "</div>" +

        "<div style='display:block;font-weight: normal;'> TotalPrice: <b>" + rowObj.price + " Rs</b></div>" + "<div style='display:block;font-weight: normal;'> Customer:<b>" + rowObj.customerName +
        "</b></div>" + // "<div style='display:block;font-weight: normal;'> Ph:<b>" + rowObj.contactNum +
         "<div style='display:block;font-weight: normal;'> Ph:<b> <a href='tel:"+rowObj.contactNum+"'>" + rowObj.contactNum + "</a>"+
        "</b></div>" + "<div style='display:block;font-weight: normal;'> Address: Block <b>" + block + '</b> Door <b>' + door + "</b></div>" + "<div style='display:block;font-weight: normal;'> Status:<b>" + rowObj.status + "</b></div>" + "<div style='display:block;font-weight: normal;'> Customer Comments: <b>" + comment + "</b></div>" + "<div style='display:block;font-weight: normal;'>Vendor Comments: <b>" + vendor_comment + "</b></div>";

        return display;
    },
    svVendorOrderHistoryResult: function(inSender, inDeprecated) {

        if (this.svVendorOrderHistory.getCount() > 0) {
            this.panelNoResults.setShowing(false);

        } else {
            this.panelNoResults.setShowing(true);
        }
    },
    list3Select2: function(inSender, inItem) {
        wm.Page.getPage("MVendorHomePg").vPageBack = "ORDER_HISTORY";
    },
    list3CommentFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        var buttonText = '<img src ="resources/images/mobile/next_img.png" height="26px" />';
        return buttonText;
    },
    lvOrderItemsSuccess: function(inSender, inDeprecated) {
        var display = ""; //" <div style='display:block;font-weight: normal;'> <b>";
        for (var count = 0; count < this.lvOrderItems.getCount(); count++) {

            var vItem = this.lvOrderItems.getItem(count);
            var unit = vItem.data.items.data.unit;

            if (!unit || unit === null) {
                unit = "";
            }
            display = display + " <div style='display:block;font-weight: normal;'> <b> &nbsp;&nbsp;";
            display = display + vItem.data.items.data.itemName + "," + vItem.data.price + "Rs (" + vItem.data.quantity + " " + unit + " @" + vItem.data.items.data.price + "Rs)";
            display = display + "</br> ";
            display = display + "</b></div> ";
        }

        this.labelOrderDetailsList.setCaption(display);
    },
    _end: 0
});